
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

/***********************************************************************
* vw Name: dbo.vw_factors
* Created: 20091211, RGM
* Purpose: factor para calcular las toneladas de maiz que se requieren
*	por tonelada de producto, para lo que se lee: 
*	1 ton de 'item_id' necesita 1 * 'factor' de ton de maiz
*
* Modified: 20091228 RGM, se agrega valor de 99 para plantas que no esten
*	definidas en el CASE, es decir, alguna nueva ademas de PJS, PTL y PPA
*
* HistoryDate.
* yyyymmdd User, data
* 
* Note: nothing
* 
***********************************************************************/
ALTER VIEW [dbo].[vw_factors] AS
SELECT DISTINCT p.plant_id, i.item_id, mp.month_period_id, scf.factor, 
		CASE p.plant_id 
			WHEN 3303 THEN 1
			WHEN 3304 THEN 2
			WHEN 3302 THEN 3
			ELSE 99
		END production_order
	FROM sap_corn_factor scf, plants p, vw_items i, months_periods mp
	WHERE scf.plant = p.plant_id
		AND scf.material = i.item_id
		AND scf.fiscal_year = mp.year
		AND scf.period = mp.month
GO

SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO

